package org.linloong.config.typehandler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * @Author: kw
 * @date: 2025-10-18 15:01
 */
@Configuration
public class TypeHandlerConfig {
    @Bean
    public JSONObjectTypeHandler fastJSONObjectTypeHandler() {
        return new JSONObjectTypeHandler();
    }
    @Bean
    public JSONArrayTypeHandler fastJSONArrayTypeHandler() {
        return new JSONArrayTypeHandler();
    }

    @Bean
    public GenericListTypeHandler floatListTypeHandler() {
        // 创建List<Float>类型
        ParameterizedType floatListType = new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {
                return new Type[]{Float.class};
            }

            @Override
            public Type getRawType() {
                return List.class;
            }

            @Override
            public Type getOwnerType() {
                return null;
            }
        };
        return new GenericListTypeHandler(floatListType, Float.class);
    }

    @Bean
    public GenericListTypeHandler sensorLayoutListTypeHandler() {
        // 创建List<DeviceInfo.SensorLayout>类型
        ParameterizedType sensorLayoutListType = new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {
                return new Type[]{org.linloong.modules.apis.monitor.entity.DeviceInfo.SensorLayout.class};
            }

            @Override
            public Type getRawType() {
                return List.class;
            }

            @Override
            public Type getOwnerType() {
                return null;
            }
        };
        return new GenericListTypeHandler(sensorLayoutListType, org.linloong.modules.apis.monitor.entity.DeviceInfo.SensorLayout.class);
    }
}